package guyubao.com.controller.admin;

import guyubao.com.controller.BaseController;
import guyubao.com.controller.MessageChannelController;
import guyubao.com.entity.RestBean;
import guyubao.com.entity.vo.request.MessageChannelVoRequest;
import guyubao.com.entity.vo.response.MessageChannelVo;
import guyubao.com.service.MessageChannelService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Validated
@RestController
@RequestMapping("/api/admin/messageChannel")
@Tag(name = "消息渠道相关", description = "消息渠道的增删改查")
public class AdminMessageChannelController extends BaseController {
    @Resource
    MessageChannelController messageChannelController;
    @Resource
    MessageChannelService messageChannelService;
    // 获得消息渠道信息
    @Operation(summary ="根据uId查询消息渠道")
    @GetMapping("/uId")
    public RestBean<MessageChannelVo> getMessageChannel(@RequestParam String uid,
                                                        @RequestAttribute String role){
        if(!isAdmin(role))return RestBean.forbidden("您不是管理员");
        return messageChannelController.innerGetMessageChannel(uid);
    }
    // 修改消息渠道信息
    @Operation(summary = "根据uId修改消息渠道")
    @PutMapping("/update")
    public RestBean<Void> updateMessageChannel(@RequestBody MessageChannelVoRequest vo,
                                               @RequestAttribute String role){
        if(!isAdmin(role))return RestBean.forbidden("您不是管理员");
        return messageChannelController.innerUpdateMessageChannel(vo);
    }
    @Operation(summary = "群体发送消息")
    @PostMapping("/sends")
    public RestBean<Void> sendMessageChannel(@RequestParam String txt,
                                             @RequestAttribute String role){
        if(!isAdmin(role))return RestBean.forbidden("您不是管理员");
        return this.messageHandle(txt,messageChannelService::sendMessages);
    }
}
